package org.example.event;

import lombok.Getter;
import org.springframework.context.ApplicationEvent;

@Getter
public class MyApplicationEvent2 extends ApplicationEvent {

    private final Object data;

    public MyApplicationEvent2(MyEventSource source, Object data) {
        super(source);
        this.data = data;
    }

    @Override
    public String toString() {
        return "MyApplicationEvent2{" +
                "timestamp=" + getTimestamp() +
                ", source=" + getSourceName() +
                ", data=" + data +
                '}';
    }

    private String getSourceName() {
        return ((MyEventSource) getSource()).getName();
    }
}
